package com.example.lzy.listviewsample.AdapterViewFilpper;

import android.os.Build;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterViewFlipper;
import android.widget.Button;

import com.example.lzy.listviewsample.R;

public class AdapterViewFilperActivity extends AppCompatActivity implements View.OnClickListener {

    private AdapterViewFlipper adapterViewFlipper = null;
    private Button btn1 = null;
    private Button btn2 = null;
    private Button btn3 = null;

    private int[] ids = {
        R.drawable.timg_1,R.drawable.timg_2,R.drawable.timg_3};
    @RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.adapterview_filpper_layout);

        adapterViewFlipper = (AdapterViewFlipper) findViewById(R.id.flipper);
        btn1 = (Button) findViewById(R.id.last);
        btn2 = (Button) findViewById(R.id.next);
        btn3 = (Button) findViewById(R.id.auto);

        MyFilpperAdapter adapter = new MyFilpperAdapter(this,ids);
        adapterViewFlipper.setAdapter(adapter);

        btn1.setOnClickListener(this);
        btn2.setOnClickListener(this);
        btn3.setOnClickListener(this);

    }

    @RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.last:
                adapterViewFlipper.showPrevious();
                adapterViewFlipper.stopFlipping();
                break;
            case R.id.next:
                adapterViewFlipper.showNext();
                adapterViewFlipper.stopFlipping();
                break;
            case R.id.auto:
                adapterViewFlipper.startFlipping();
                break;
            default:
                break;
        }
    }
}
